package com.egor.data.entity;

import com.egor.data.enums.OrderStatus;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.Objects;

@Entity
@Table(name = "orders")
@Getter
@Setter
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Column(name = "order_name", nullable = false)
    @NotEmpty
    private String name;

    @Column(name = "order_address", nullable = false)
    @NotEmpty
    private String address;

    @Column(name = "date_of_order", nullable = false)
    @CreationTimestamp
    private LocalDate dateOfOrder;

    @Column(name = "order_status", nullable = false)
    @NotNull
    private OrderStatus orderStatus;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Order order)) return false;
        return Objects.equals(id, order.id) &&
                Objects.equals(name, order.name) &&
                Objects.equals(address, order.address) &&
                Objects.equals(dateOfOrder, order.dateOfOrder);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, address, dateOfOrder);
    }
}
